#ifndef __CONTROLBASE__
#define __CONTROLBASE__

#include "..\Schematics\Schematic.h"
#include "..\Rendering\RendererBase.h"
#include "..\Rendering\Viewport.h"
#include "MouseButton.h"
#include "..\Rendering\IRefresh.h"

class ControlBase : public IRefresh
{
protected:
	Schematic *_schematic;
	Viewport _viewport;

	/// <summary>
	/// Reset all values to default.
	/// </summary>
	virtual void ResetValues() = 0;

public:
	/// <summary>
	/// Get or set the renderer that this control uses.
	/// </summary>
	RendererBase *Renderer;

	/// <summary>
	/// Constructor.
	/// </summary>
	/// <param name="viewport">The viewport to render.</param>
	ControlBase(const Viewport &viewport, RendererBase *renderer) :
		_viewport(viewport),
		Renderer(renderer),
		_schematic(nullptr)
	{
		renderer->RegisterRefresher(this);
	}

	virtual ~ControlBase()
	{
	}

	/// <summary>
	/// Get the width of the control.
	/// </summary>
	virtual int GetWidth() const = 0;

	/// <summary>
	/// Get the height of the control.
	/// </summary>
	virtual int GetHeight() const = 0;

	/// <summary>
	/// Get or set the schematic being rendered.
	/// </summary>
	Schematic *GetSchematic() const { return _schematic; }
	void SetSchematic(Schematic *value);

	/// <summary>
	/// Get or set the viewport this control is rendering.
	/// </summary>
	const Viewport &GetViewport() const { return _viewport; }
	void SetViewport(const Viewport &viewport)
	{
		_viewport = viewport;
		Reset();
	}
		
	/// <summary>
	/// Reset all values to default and refresh.
	/// </summary>
	virtual void Reset()
	{
		ResetValues();
		Refresh();
	}

	/// <summary>
	/// Handle the mousedown event.
	/// </summary>
	/// <param name="position">Position of the mouse.</param>
	/// <param name="button">Button being pressed.</param>
	virtual void MouseDown(const Point2i &position, const MouseButton &button) = 0;

	/// <summary>
	/// Handle the mousemove event.
	/// </summary>
	/// <param name="position">Position of the mouse.</param>
	/// <param name="button">Button being pressed.</param>
	virtual void MouseMove(const Point2i &position, const MouseButton &button) = 0;

	/// <summary>
	/// Handle the mouseup event.
	/// </summary>
	/// <param name="position">Position of the mouse.</param>
	/// <param name="button">Button being pressed.</param>
	virtual void MouseUp(const Point2i &position, const MouseButton &button) = 0;

	/// <summary>
	/// Handle the mousewheel event.
	/// </summary>
	/// <param name="detents">Detents of the wheel.</param>
	virtual void MouseWheel(const int &detents) = 0;

	/// <summary>
	/// Handle the draw event.
	/// </summary>
	virtual void Draw() = 0;

	/// <summary>
	/// Get the handle associated with this control.
	/// </summary>
	virtual void *GetHandle() const = 0;
};
#endif